package cn.hchaojie.cts;

import javafx.event.EventHandler;
import javafx.geometry.HorizontalDirection;
import javafx.scene.input.KeyEvent;

public class KeyEventHandler implements EventHandler<KeyEvent> {
	GameController controller;

	public KeyEventHandler(GameController controller) {
		this.controller = controller;
	}

	@Override
	public void handle(KeyEvent event) {
		event.consume();	// 防止事件继续传播
		if (controller.pausedProperty().get()) {
			return;
		}

		switch (event.getCode()) {
		case LEFT:
			controller.move(HorizontalDirection.LEFT);
			break;
			
		case RIGHT:
			controller.move(HorizontalDirection.RIGHT);
			break;
			
		case UP:
			controller.rotate();
			break;

		case DOWN:
		case SPACE:
			controller.speedUp();
			break;

		default:
			break;
		}
	}
}
